class Solution {
public:
    int missingNumber(vector<int>& nums) {
        int n =nums.size();
        int left = 0;
        int right = n-1;
        while(left<right)
        {
            int mid = left+(right-left)/2;
            if(mid==nums[mid])
            {
                left = mid+1;
            }
            else 
                right = mid;
        }
        return left==nums[left]?nums[left]+1:left;
    }
};